package sourceagile.server.utilities;

import java.io.File;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

public class ConvertFileToJson {

	public static String FILE_PATH = "filePath";

	public static String FILE_NAME = "fileName";

	public static String DATE_MODIFIED = "dateModified";

	public static String FILE_AUTHOR = "fileAuthor";

	public static JSONObject convertFromGit(File file, String projectPath) {

		JSONObject entry = new JSONObject();

		try {

			if (file.getParent().length() > projectPath.length()) {

				entry.put(FILE_PATH,
						file.getParent().substring(projectPath.length() + 1));

			} else {

				entry.put(FILE_PATH, "");
			}

			entry.put(FILE_NAME, file.getName());

			entry.put(DATE_MODIFIED, file.lastModified());

			// entry.put(FILE_AUTHOR, file.getAuthor());

		} catch (JSONException e) {

			e.printStackTrace();
		}

		return entry;
	}

	public static JSONObject convertFeaturesFromGit(String path, String name) {

		JSONObject entry = new JSONObject();

		try {

			entry.put(FILE_PATH, path);

			entry.put(FILE_NAME, name);

			// entry.put(DATE_MODIFIED, subversionEntry.getDate().getTime());

			// entry.put(FILE_AUTHOR, subversionEntry.getAuthor());

		} catch (JSONException e) {

			e.printStackTrace();
		}

		return entry;
	}

	public static JSONObject convertFileFromLocal(File file, String projectPath) {

		JSONObject entry = new JSONObject();

		try {

			if (file.getParent().length() > projectPath.length()) {

				entry.put(FILE_PATH,
						file.getParent().substring(projectPath.length() + 1));

			} else {

				entry.put(FILE_PATH, "");
			}

			entry.put(FILE_NAME, file.getName());

			// entry.put(DATE_MODIFIED, subversionEntry.getDate().getTime());

			// entry.put(FILE_AUTHOR, subversionEntry.getAuthor());

		} catch (JSONException e) {

			e.printStackTrace();
		}

		return entry;
	}
}
